/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

//package com.nokia.midp.examples.svg;




import java.io.InputStream;
import javax.microedition.lcdui.*;
import javax.microedition.media.*;
import javax.microedition.midlet.*;
import javax.microedition.m2g.*;
import javax.xml.parsers.*;


/**
 * Simple midlet that displays an animation using SVGAnimator,
 * It also demonstrates how SVGEventListener works.
 */
public class SvgAnimatorMidlet extends MIDlet implements CommandListener {

  private SVGAnimator svgAnimator;
  private Command cmExit;
/**
 * Constructor.
 */
    public SvgAnimatorMidlet() {

// *** load a test svg image

        SVGImage svgImage = null;
    	try {
	        InputStream svgStream = getClass().getResourceAsStream("content3.svg");
	        svgImage = (SVGImage)( SVGImage.createImage( svgStream, null ) );
	} catch ( Exception e ){
      	    e.printStackTrace();
	    }
   
// *** setup the SVGAnimator
        svgAnimator = SVGAnimator.createAnimator( svgImage );
        svgAnimator.setSVGEventListener( new MySvgEventListener() );
        Canvas c = (Canvas)(svgAnimator.getTargetComponent());
        Display.getDisplay(this).setCurrent( c );
        c.setCommandListener(this);
        parseData();
// *** set up the midlet menu
        int hotKey = 0;
        cmExit = new Command("Exit", Command.SCREEN, hotKey++);
        c.addCommand(cmExit);

    }

public void parseData() {

    try
    {
      SAXParserFactory factory = SAXParserFactory.newInstance();
      SAXParser saxParser = factory.newSAXParser();
      InputStream is = getClass().getResourceAsStream("content3.svg");
      saxParser.parse(is,new XmlHandler(this));

    }
    catch(Exception ex) {
        System.out.println("parsing exception");
        System.out.println(ex);
    }
 
}
/**
 * Required midlet method.
 */
    public void startApp() {
	svgAnimator.play();
      
    }


/**
 * Required midlet method.
 */
    public void pauseApp() {
    }


/**
 * Required midlet method.
 */
    public void destroyApp(boolean unconditional) {
    }


/**
 * Handle the various menu actions.
 */
    public void commandAction(Command c, Displayable s) {
        if (c == cmExit) {
            destroyApp(false);
            notifyDestroyed();
       
        }
    }


}


/**
 * Simple SVGEventListener with no action taken in event handling methods.
 */
class MySvgEventListener implements SVGEventListener {
	public void keyPressed(int keyCode) {
	}

	public void keyReleased(int keyCode) {
	}

	public void pointerPressed(int x, int y) {
	}

	public void pointerReleased(int x, int y) {
	}

	public void hideNotify() {
	}

	public void showNotify() {
	}

	public void sizeChanged(int w, int h) {
	}
}
